<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<html>
	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="css/qiantai_page.css" />
		<!-- <script type="text/javascript" class="autoinsert" src="js/jquery-2.2.0.min.js"></script> -->
		<title></title>
	</head>
	<body>
		<div class="page_nav">
			<c:choose>
				<c:when test="${page.totalPageCount <= 10}">
					<!-- 如果总页数小于10，则全部显示 -->
					<c:set var="begin" value="1"></c:set>
					<c:set var="end" value="${page.totalPageCount }"></c:set>
				</c:when>
				<c:when test="${page.pageNow <= 5 }">
					<!-- 如果总页数小于5，则显示1-10页 -->
					<c:set var="begin" value="1"></c:set>
					<c:set var="end" value="10"></c:set>
				</c:when>
				<c:otherwise>
					<!-- 否则，显示前5页和后5页，保证当前页在中间 -->
					<c:set var="begin" value="${page.pageNow-5 }"></c:set>
					<c:set var="end" value="${page.pageNow+5 }"></c:set>
					<c:if test="${end > page.totalPageCount }">
						<!-- 如果end值小于总的记录数，则显示最后10页 -->
						<c:set var="end" value="${page.totalPageCount}"></c:set>
						<c:set var="begin" value="${end-10 }"></c:set>
					</c:if>
				</c:otherwise>
			</c:choose>
			<!-- <c:choose>
				<c:when test="${page.pageNow != 1 }">
					<!- 如果当前页为1，则不显示首页和上一页 ->
					<a href="?user_method=${mypage}&pageNow=1">首页</a>
					<a href="?user_method=${mypage}&pageNow=${page.pageNow-1 }">上一页</a>
				</c:when>
			</c:choose>
			<!- 遍历页码 ->
			<c:forEach begin="${begin }" end="${end }" var="index">
				<c:choose>
					<c:when test="${page.pageNow == index }">
						<!- 如果为当前页，则特殊显示 ->
						<a style="height:24px; margin:0 3px; border:none; background:#C00;">${index}</a>
					</c:when>
					<c:otherwise>
						<!- 否则，普通显示 ->
						<a href="?user_method=${mypage}&pageNow=${index}">${index }</a>
					</c:otherwise>
				</c:choose>
			</c:forEach>
			<c:choose>
				<c:when test="${page.pageNow != page.totalPageCount }">
					<!- 如果当前页为总的记录数，则不显示末页和下一页 ->
					<a href="?user_method=${mypage}&pageNow=${page.pageNow+1 }">下一页</a>
					<a href="?user_method=${mypage}&pageNow=${page.totalPageCount }">末页</a>
				</c:when>
			</c:choose> -->

			<ul class="pagination">
				<li>
					<c:choose>
						<c:when test="${page.pageNow != 1 }">
							<!-- 如果当前页为1，则不显示首页和上一页 -->
							<span><a href="?type=${type}&pageNow=1" id="first_page" style="color: blue;">首页</a></span>
							<span><a href="?type=${type}&pageNow=${page.pageNow-1 }" id="up_page" style="color: blue;">上一页</a></span>
						</c:when>
					</c:choose>
				</li>
				<li>
					<c:forEach begin="${begin }" end="${end }" var="index">
						<c:choose>
							<c:when test="${page.pageNow == index }">
								<!-- 如果为当前页，则特殊显示 -->
								<span style="background-color: #337ab7;color: #fff;"><a style="height:24px; margin:0 3px; border:none;color: #fff;">${index}</a></span>
							</c:when>
							<c:otherwise>
								<!-- 否则，普通显示 -->
								<span><a href="?type=${type}&pageNow=${index}" id="other_page" style="color: blue;">${index }</a></span>
							</c:otherwise>
						</c:choose>
					</c:forEach>
				</li>
				<li>
					<c:choose>
						<c:when test="${page.pageNow != page.totalPageCount }">
							<!-- 如果当前页为总的记录数，则不显示末页和下一页 -->
							<span><a href="?type=${type}&pageNow=${page.pageNow+1 }" id="down_page" style="color: blue;">下一页</a></span>
							<span><a href="?type=${type}&pageNow=${page.totalPageCount }" id="last_page" style="color: blue;">末页</a></span>
						</c:when>
					</c:choose>
				</li>
				<li style="margin-left: 100px;line-height: 2.3;">
					共${page.totalPageCount }页，${page.totalCount }条记录
				</li>
			</ul>

		</div>
	</body>
</html>
